﻿using LiteStep.Exchanges;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LiteStep.Fees
{
    public class SimpleFeeStructureManager : IFeeStructureManager
    {
        private IDictionary<IExchangeType, IFeeStructure> Map { get; set; }

        public SimpleFeeStructureManager()
		{
            this.Map = new Dictionary<IExchangeType, IFeeStructure>();
		}

        public void Set<TExchange>(IFeeStructure<TExchange> feeStructure)
            where TExchange : IExchange
        {
            if (feeStructure == null)
                throw new ArgumentNullException("feeStructure", "feeStructure cannot be null");

            var exchangeType = new ExchangeType<TExchange>();
            this.Map[exchangeType] = feeStructure;
        }

        public IFeeStructure<TExchange> Get<TExchange>() where TExchange : IExchange
        {
            return DoGet<TExchange>();
        }

        private IFeeStructure<TExchange> DoGet<TExchange>()
            where TExchange : IExchange
        {
            var fromType = new ExchangeType<TExchange>();

            if (this.Map == null || !this.Map.ContainsKey(fromType)) { return null; }

            return (IFeeStructure<TExchange>)this.Map[fromType];
        }
    }
}
